<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/taglib_include.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, target-densitydpi=medium-dpi, initial-scale=0.5, minimum-scale=0.5, maximum-scale=0.5, user-scalable=no" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta content="telephone=no" name="format-detection" />
<link href="${ctx}/css/main.css?ver=${main_css_version}" rel="stylesheet" type="text/css" />
<link href="${ctx}/css/tipso.min.css" rel="stylesheet" type="text/css" media="screen" />
<style type="text/css">
body {
    background-color:#e1e1e1;
}

.policyNumber {
    font-size: 16pt;
    color: #2c2c2c;
    display: block;
    float: left;
    height: 46pt;
    line-height: 46pt;
    text-align: left;
    margin-top: 6pt;
}
</style>
<title>${projectTitle }</title>
</head>
<body>
  <header id="main-top">
    <a href="${ctx}/order/list.do?pageNow=${pageNow}">
      <div id="main-top-left">
        <img src="${ctx}/images/mui_title_back_btn.png" class="img-2">
      </div>
    </a>
    <div id="main-top-title">订单详细</div>
  </header>
  <div id="container">
    <div id="order-number">订单号：${orderdetailresult.orderpnr}</div>
    <div class="f-information">
      <h3>车票信息</h3>
      <div class="f-information-x">
        <div>
                             发/到站:
          <span class="font-18-b"> ${orderdetailresult.startStationName} - ${orderdetailresult.arriveStationName}</span>
        </div>
        <div>
                               发车时间:
          <span class="font-18-b" id="font-t-12">${orderdetailresult.leaveDate} ${orderdetailresult.leaveTime}</span>
        </div>
        <div>
                               班次类型:
          <span class="font-18-b">
              ${cf:schTypeName(orderdetailresult.schType) }
          </span>
        </div>
        <div>
                               班次:
          <span class="font-18-b">${orderdetailresult.regBusNo}</span>
        </div>
        <div>
                               车型:
          <span class="font-18-b">${orderdetailresult.busTypeName}</span>
        </div>
        <div>
                               票价:
           <span class="font-18-b" style="width: 100%;font-size: 16pt;"> ￥${orderdetailresult.totalPrice}<span id="totalserviceprice" style="width: 100%;font-size: 16pt;"></span></span>
        </div>
        <div>
                               票数:
          <span class="font-18-b">${orderdetailresult.ticketNum}张</span>
        </div>
        <div>
                            购票时间:
          <span class="font-18-b">${orderdetailresult.placeOrderDatetime}</span>
        </div>
      </div>
    </div>
    <form action="" id="form">
      <div class="passenger">
        <c:if test="${haspassengerinfo==constant.has_passenginfo}">
          <h3>乘车人</h3>
        </c:if>
        <div id="often-passenger">
          <input type="hidden" name="orderId" value="${orderdetailresult.orderId}"/>
          <input type="hidden" name="stationId" value="${orderdetailresult.startStationId}" />
          <ul>
            <c:if test="${haspassengerinfo==constant.has_passenginfo}">
               <c:forEach items="${orderdetailresult.ticketList}" var="ticket" varStatus="status">
                  <li style="height: 60pt;border-bottom: 0px;">
                    <div class="check">
                      <c:if test="${ticket.ticketState==constant.ticket_success||ticket.ticketState==constant.collected_ticket}">
                          <input type="checkbox" value="${ticket.ticketId}" name="ticketinfos[${status.index}].checkbox" id="checkbox${ticket.ticketId}" checked="checked"/>
                      </c:if>
                      <c:if test="${ticket.ticketState==constant.refunded||ticket.ticketState==constant.refunded_rebate_fail||ticket.ticketState==constant.refunded_rebating}">
                          <input type="checkbox" value="${ticket.ticketId}" name="ticketinfos[${status.index}].checkbox" id="checkbox${ticket.ticketId}" disabled="disabled"/>
                      </c:if>
                      <c:if test="${ticket.ticketState==constant.initialize}">
                          <input type="checkbox" value="${ticket.ticketId}" name="ticketinfos[${status.index}].checkbox" id="checkbox${ticket.ticketId}" disabled="disabled" checked="checked"/>
                      </c:if>
                      <c:if test="${ticket.ticketState==constant.ticketed_fail}">
                          <input type="checkbox" value="${ticket.ticketId}" name="ticketinfos[${status.index}].checkbox" id="checkbox${ticket.ticketId}" disabled="disabled"/>
                      </c:if>
                      <input type="hidden" value="${ticket.ticketId}" id="ticketId${status.index}" name="ticketinfos[${status.index}].ticketId">
                    </div>
                    <div class="name-1" data-tipso="${ticket.fullname}" style="white-space:nowrap;text-overflow:ellipsis;overflow:hidden;">
                       ${ticket.fullname}
                       <input type="hidden" value="${ticket.fullname}" id="fullname${status.index}" name="ticketinfos[${status.index}].fullname">
                    </div>
                    <div class="ticket-1" <c:if test="${ticket.carryFreeTicketFlag==constant.carry}">freeTicketFlag="1" data-tipso="免票携童1"</c:if> style="white-space:nowrap;text-overflow:ellipsis;overflow:hidden;">
                       ${ticket.ticketTypeName}
                    </div>
                    <div class="Document-type-1">
                        ${cf:identificationTypeName(ticket.identificationType)} 
                        ${cf:hiddenIdentificationNumber(ticket.identificationNumber,ticket.identificationType)}
                        <input type="hidden" value="${ticket.identificationNumber}" id="identificationNumber${status.index}" name="ticketinfos[${status.index}].identificationNumber">
                        <input type="hidden" value="${ticket.identificationType}" id="identificationType${status.index}" name="ticketinfos[${status.index}].identificationType">
                        <input type="hidden" value="${orderdetailresult.regBusNo}" id="regBusNo${status.index}" name="ticketinfos[${status.index}].regBusNo">
                        <input type="hidden" value="${orderdetailresult.startStationId}" id="startStationId${status.index}" name="ticketinfos[${status.index}].startStationId">
                        <input type="hidden" value="${orderdetailresult.arriveStationId}" id="arriveStationId${status.index}" name="ticketinfos[${status.index}].arriveStationId">
                        <input type="hidden" value="${orderdetailresult.leaveDate}" id="leaveDate${status.index}" name="ticketinfos[${status.index}].leaveDate">
                        <input type="hidden" value="${orderdetailresult.leaveTime}" id="leaveTime${status.index}" name="ticketinfos[${status.index}].leaveTime">
                    </div>
                    <div class="print-tick"><span id="ticketstatename${ticket.ticketId}"> ${cf:ticketStateName(ticket.ticketState)} </span></div>
                  </li>
                  <li style="height:28pt;padding-bottom:25px;border-bottom:1px solid #b2b2b2">
                    <div class="check">
                    </div>
                    <div class="policyNumber">
                        <c:if test="${ticket.policyNumber !=null && ticket.policyNumber != ''}">
                                                                  保单号:${ticket.policyNumber}
                        </c:if>
                    </div>
                    <c:if test="${cf:isEnableQRCheckin(orderdetailresult.startStationId) && orderdetailresult.statusCode == constant.order_status_paid}">
                      <div data-ticketid="${ticket.ticketId}" class="ticket-1" style="color:#0080DC;">打开条码</div>
                    </c:if>
                    <div class="Document-type-1"></div>
                    <div class="print-tick"></div>
                  </li>
               </c:forEach>
             </c:if>
          </ul>
        </div>
      </div>
   </form>
  </div>

  <c:if test="${orderdetailresult.statusCode == constant.order_status_paid}">
     <c:if test="${refundButtonEnabled == true}">  
	       <c:if test="${!startStationDisableRefund}">
	            <a href="javascript:void(0);" id="refund">
	                <div id="q-button">
	                  <div id="determine" style="letter-spacing: 0pt;" refundticket="refundticket">在线退票</div>
	                </div>
	              </a>
	       </c:if>
    </c:if>
  </c:if>
  <span style="display: block;width: 100%;text-align: center;margin-top: 15px;font-size: 20pt;display: none;color:#FF4500;" id="message">退票成功</span>

  <%@ include file="/WEB-INF/views/popup_alert.jsp"%>
  <%@ include file="/WEB-INF/views/popup_confirm.jsp"%>
  <%@ include file="/WEB-INF/views/loading.jsp"%>
  <script type="text/javascript" src="${ctx}/js/jquery.min.js?ver=${jquery_min_version}"></script>
  <script type="text/javascript" src="${ctx}/js/tipso.min.js"></script>
  <script type="text/javascript" src="${ctx}/js/JsBarcode.code128.min.js"></script>
  <!-- mergeTo:${ctx}/js/custom.min.js?ver=${custom_min_version} -->
  <script type="text/javascript" src="${ctx}/js/custom.js?ver=${custom_version}"></script>
  <!-- mergeTo -->
  <script type="text/javascript">
     var nowtime = new Date(); // 当前时间

     $(function(){
         var leavetime = $("#font-t-12").text();
         var ticketIds = '';
         var totalservice = "${totalService}";
         var totalinsurance = "${totalInsurance}";
         var zerodouble = "${constant.zero_double}";
         var isShanXi = "${isShanXi}";

         var totalmoney = parseFloat(totalservice);
         var totalmoneyinsurance = parseFloat(totalinsurance);
         
         var totalPrivilegeAmount ="${totalPrivilegeAmount}";
         var str = "";
         if(totalPrivilegeAmount != ""){  	
        	 if(totalinsurance != zerodouble){
        		 str = "(含服务费￥" + totalmoney.toFixed(2) + ",已优惠￥" + parseFloat(totalPrivilegeAmount).toFixed(2) + ",保费￥" + totalmoneyinsurance.toFixed(2) +")";
        	 }else{
        		 str = "(含服务费￥" + totalmoney.toFixed(2) + ",已优惠￥" + parseFloat(totalPrivilegeAmount).toFixed(2) + ")";
        	 }
             $("#totalserviceprice").html(str);
         } else {
        	 if(totalinsurance != zerodouble){
        		 str = "(含服务费￥" + totalmoney.toFixed(2) + ",保费￥" + totalmoneyinsurance.toFixed(2) + ")";
        	 }else{
        		 str = "(含服务费" + totalmoney.toFixed(2) + ")";
        	 }
        	 $("#totalserviceprice").html(str);
         }
         //var departureTime = new Date(leavetime.replace("-", "/").replace("-", "/")); //发车时间
         //判断时间，如果已经开车就不能进行退票操作
//          if(nowtime > departureTime){
//              $("#refund").css("display","none");
//          }

         $("div[refundticket='refundticket']").bind("click",function(e){
              var checkboxlist = $("ul").find("input[type='checkbox']:checked");
              if(checkboxlist.length == 0){
                    openAlert("请选择一个乘车人");
                    return false;
              }

             var msg = "";
             $.post("${ctx}/refund/returnamount.do",$("#form").serialize(),function(data){
                 if(data.errcode != 0){
                     openAlert(data.errmsg);
                 } else {
                     if(isShanXi == "true"){
                         msg = "按照交通部《汽车客运站收费规则》和陕西省交通厅，物价局《汽车客运站收费规则》的相关规定，本次退票金额为"
                             + "<span style='color:#FF4500;' id='returnamount'>￥" + data.totalReturnAmount +"元</span>";
                     } else {
                         msg = "按照交通部《汽车客运站收费规则》和四川省交通厅，物价局《汽车客运站收费规则》的相关规定，本次退票金额为"
                             + "<span style='color:#FF4500;' id='returnamount'>￥" + data.totalReturnAmount +"元</span>";
                     }
                     openConfirmDialog(msg,function(){
                         $.post("${ctx}/refund/refundticket.do",$("#form").serialize(),function(data){
                             var checkboxlist = $("ul").find("input[type='checkbox']:checked");
                             var totalcheckboxlist = $("ul").find("input[type='checkbox']").length;
                             var disabledcheckboxlist = $("ul").find("input[disabled='disabled']").length;
                             var refundnum = 0;
                             var failrefundnum = 0;
                             var checkboxlen = checkboxlist.length;
                             var resultmsg = "";
                             $("#message").show("slow",function(){
                                 jQuery.each(data,function(index,item){
                                     if(item.errcode === 0){
                                         resultmsg += item.fullname + "的票退票成功" + "<br/>";
                                         $("#checkbox" + item.ticketId).attr("disabled","disabled");
                                         $("#ticketstatename" + item.ticketId).text("已退票");
                                         $("#checkbox" + item.ticketId).removeAttr("checked");
                                         refundnum++;
                                     }else{
                                         resultmsg += item.fullname + item.errmsg + "<br/>";
                                     }
                                 });
                                 $("#message").html(resultmsg);
                                 //退票成功数量
                                 var refundsuccessnum = parseInt(refundnum) + parseInt(disabledcheckboxlist);
                                 if(parseInt(refundsuccessnum) == parseInt(totalcheckboxlist)){
                                     $("#refund").css("display","none");
                                 }
                             }).delay(7000).hide(300);
                         });
                     });
                 }
             });
         });
     });
     $("div[data-ticketid]").on("click", function() {
         var ticketId = $(this).attr("data-ticketid");
         var jqAlertContent = $("#alert-thickness-concent");
         // 生成条码
         jqAlertContent.html("<div>扫描条码检票</div><img id='barcode' />");
         $("#barcode").JsBarcode(ticketId, {
             displayValue:true,
             fontSize:16,
             width:4,
             height:100
         });
         openAlert("");
     });
     // 设置乘客姓名tips，解决姓名过长的显示问题
     var passengerNameJqObj = $("div[class='name-1']");
     passengerNameJqObj.tipso(
             {useTitle: false,
              background: 'tomato',
              onShow:function(){
                  t = setTimeout(function(){
                	  passengerNameJqObj.tipso('hide');
                  }, 1500);
                }
              });
     
     // 显示免票提示信息
     var freeTicketNumJqObj = $("div[freeTicketFlag='1']");
     freeTicketNumJqObj.tipso(
             {useTitle: false,
              background: 'tomato',
              onShow:function(){
                  t = setTimeout(function(){
                      passengerNameJqObj.tipso('hide');
                  }, 1500);
                }
              });
  </script>
</body>
</html>